//
//  PersonalHomePageViewController.m
//  WeCommunity
//
//  Created by mac on 2017/8/7.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "PersonalHomePageViewController.h"
#import "PersonalHomepageView.h"
#import "HomePageDynamicDetailViewController.h"
#import "FullScreenImage.h"

@interface PersonalHomePageViewController ()<PersonalHomepageDelegate>

@property (nonatomic,strong) PersonalHomepageView * homepageView;

@end

@implementation PersonalHomePageViewController

#pragma mark - get
-(PersonalHomepageView *)homepageView
{
    if(!_homepageView){
        _homepageView = [[PersonalHomepageView alloc] initWithFrame:CGRectMake(0, 0, KScreen_Width, KScreen_Height - KNaviheight)];
        _homepageView.delegate = self;
    }
    return _homepageView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initWithUserInterface];

    [self loadContactData];

//    [self addVisitRecord];
}



-(void)initWithUserInterface
{
    self.title = KNSLocal(@"详细资料");

    self.view.backgroundColor = [UIColor colorWithHex:0xf8f8f8 alpha:1.0];
    
    [self.view addSubview:self.homepageView];
    
}

-(void)loadContactData
{
    self.homepageView.contact = self.contact;
    
    [self.homepageView reloadWithData];
}

#pragma mark -  添加拜访记录
-(void)addVisitRecord
{
    //自己无法添加自己
    if([self.contact.objectId isEqualToString:[UserInfoManger shared].contact.objectId]){
        return;
    }
    [[UserServer shared] mySelfVisitSomePerson:self.contact.objectId complete:^(BOOL success, NSString *error) {
        if (success) {
            NSLog(@"添加拜访记录成功！");
        }else{
            NSLog(@"添加拜访记录失败！");
        }
    }];
}

#pragma mark - delegate
-(void)personalHomepageViewSelectRowAtIndex:(NSInteger)index
{
    if (![self canProcessNext]) {
        return;
    }
    if(index == 3){
        HomePageDynamicDetailViewController * detailVC = [[HomePageDynamicDetailViewController alloc] init];
        detailVC.contact = self.contact;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

-(void)processPersonInfoCellWithSender:(UIView *)sender
{
    NSMutableArray * fullImageArray = [NSMutableArray array];
    FullScreenImage * imageModel = [FullScreenImage new];
    imageModel.fullImagePath = self.contact.headImage;
    imageModel.showImageView = (UIImageView *)sender;
    [fullImageArray addObject:imageModel];

    DealPhotosView * dealPhotosView = [[DealPhotosView alloc] init];
    [dealPhotosView setFullScreenWithImageArray:fullImageArray showIndex:0];
    [[[UIApplication sharedApplication].delegate window] addSubview:dealPhotosView];
}

@end
